# -*- coding = utf-8 -*-
# @Time : 2023/5/29 10:22
# @Author : GHHHHHHHHH
# @File : algorithmController.py
# @Software : PyCharm
import json

from flask import Blueprint, request, jsonify

from service import AlgorithmService
from controller import algorithm

class AlgorithmController:

    @staticmethod
    @algorithm.route("/test", methods=['GET', 'POST'])
    def select_username():
        return AlgorithmService.select_username("288")

    @staticmethod
    @algorithm.route('/ocr', methods=['POST'])
    def ocr():
        image = request.files.get('image').read()
        return AlgorithmService.ocr(image)

    @staticmethod
    @algorithm.route('/plate/start', methods=['GET', 'POST'])
    def plate_start():
        return jsonify(AlgorithmService.plate_start())

    @staticmethod
    @algorithm.route('/plate/end', methods=['GET', 'POST'])
    def plate_end():
        return jsonify(AlgorithmService.plate_end())

    @staticmethod
    @algorithm.route('/save/plate', methods=['POST'])
    def save_plate():
        data = request.get_data()
        data = json.loads(data)
        plate = data['plate']
        return jsonify(AlgorithmService.save_plate(plate))

    @staticmethod
    @algorithm.route('/bayonet/msg', methods=['POST'])
    def bayonet_msg():
        # 根据用户id获取卡口信息
        data = request.get_data()
        data = json.loads(data)
        user_id = data['user_id']
        return jsonify(AlgorithmService.bayonet_msg(user_id))

    @staticmethod
    @algorithm.route('/bayonet/passed/company', methods=['POST'])
    def bayonet_passed_company():
        # 根据卡口id获取通过属于公司的车辆信息
        data = request.get_data()
        data = json.loads(data)
        bayonet_id = data['bayonet_id']
        return jsonify(AlgorithmService.bayonet_passed_company(bayonet_id))

    @staticmethod
    @algorithm.route('/bayonet/passed/private', methods=['POST'])
    def bayonet_passed_private():
        # 根据卡口id获取通过不属于公司的车辆信息
        data = request.get_data()
        data = json.loads(data)
        bayonet_id = data['bayonet_id']
        return jsonify(AlgorithmService.bayonet_passed_private(bayonet_id))

    @staticmethod
    @algorithm.route('/bayonet/getdriver', methods=['POST'])
    def bayonet_get_driver():
        # 根据车牌号获取司机信息
        data = request.get_data()
        data = json.loads(data)
        car_number = data['car_number']
        passed_time = data['passed_time']
        return jsonify(AlgorithmService.bayonet_get_driver(car_number, passed_time))

    @staticmethod
    @algorithm.route('/infoDep/lineChart', methods=['GET'])
    def infoDep_infoDep():
        # 预测数据折线图数据API
        return jsonify(AlgorithmService.infoDep_infoDep())

    @staticmethod
    @algorithm.route('/baidu/map', methods=['POST'])
    def baidu_map_get_place():
        # 根据经纬度返回地理信息
        data = request.get_data()
        data = json.loads(data)
        l1 = data['location1']
        l2 = data['location2']
        return jsonify(AlgorithmService.baidu_map_get_place(l1, l2))

    @staticmethod
    @algorithm.route('/infoDep/pieChart', methods=['GET'])
    def infoDep_pieChart():
        """
        库存车辆占比API
        :return:
        """
        return jsonify(AlgorithmService.infoDep_pieChart())

    @staticmethod
    @algorithm.route('/infoDep/ledarChart', methods=['GET'])
    def infoDep_ledarChart():
        return jsonify(AlgorithmService.infoDep_ledarChart())

    @staticmethod
    @algorithm.route('/infoDep/getmsg', methods=['GET'])
    def get_info_msg():
        return jsonify(AlgorithmService.get_info_msg())

    @staticmethod
    @algorithm.route('/bayonet/getcar', methods=['GET'])
    def get_car():
        currentpage = int(request.args.get('currentpage', type=int, default=None))
        pagesize = int(request.args.get('pagesize', type=int, default=None))
        is_registration = int(request.args.get('is_registration', type=int, default=None))
        return jsonify(AlgorithmService.get_car(currentpage, pagesize, is_registration))

    @staticmethod
    @algorithm.route('/ftp')
    def ftp_server():
        image = request.files.get('image')
        _id = request.form['id']
        return jsonify(AlgorithmService.ftp_server(image, _id))





